﻿

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>个人所得税计算</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      color: #333;
      margin: 0;
      padding: 20px;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    h1 {
      color: #007BFF;
    }
    .container {
      background: white;
      border-radius: 10px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      padding: 20px;
      width: 300px;
      text-align: center;
    }
    input[type="number"], input[type="text"] {
      width: 100%;
      padding: 10px;
      margin: 10px 0;
      border: 1px solid #ccc;
      border-radius: 5px;
      box-sizing: border-box;
    }
    button {
      background-color: #007BFF;
      color: white;
      border: none;
      padding: 10px;
      border-radius: 5px;
      cursor: pointer;
      width: 100%;
      transition: background-color 0.3s;
    }
    button:hover {
      background-color: #0056b3;
    }
    #result {
      margin-top: 20px;
      padding: 10px;
      border: 1px solid #ddd;
      border-radius: 5px;
      background-color: #f9f9f9;
    }
    label {
      font-weight: bold;
    }
  </style>
</head>
<body>
<div class="container">
  <h1>个人所得税计算</h1>
  <label for="salaryInput">工资：</label>
  <input type="number" id="salaryInput" min="0" placeholder="请输入工资" />
  <button onclick="calculateTax()">计算</button>
  <div id="result"></div>
  <label for="taxOutput">个人所得税：</label>
  <input type="text" id="taxOutput" disabled />
</div>

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
  function calculateTax() {
    var salary = parseFloat(document.getElementById("salaryInput").value);
    axios.post("http://localhost:8083/calculate_tax?salary=" + salary)
            .then((response) => {
              console.log(response.data);
              var resultDiv = document.getElementById("result");
              resultDiv.innerHTML =
                      "税率：" + response.data.taxRate + "%<br>" +
                      "税额：" + response.data.taxAmount + "<br>" +
                      "净收入：" + response.data.netIncome;

              var taxOutput = document.getElementById("taxOutput");
              taxOutput.value = response.data.taxAmount;
            })
            .catch((error) => {
              alert('请求发生错误，请检查输入或后端服务。');
            });
  }
</script>
</body>
</html>
